package com.vivo.security.jni;

import java.io.File;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.nio.charset.Charset;

import org.apache.commons.io.FileUtils;

/**
 * todo 此处的算法在计算长度较低的数据时候不会出错，当数据较长的时候最后八个字节会出错
 */
public class Base64Util {
    public static Charset UTF8_CHARSET = Charset.forName("UTF-8");
    public static byte[] charArray = "Q8vN-ryaEJGoTWOtK_qMkh5RZ6LxcUA3dnzeHu2XjSbVsFYwfPD94C0lm1Ip7gBi".getBytes(UTF8_CHARSET);

    public static int hashIndex[] = {
            0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
            0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
            0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
            0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
            0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
            0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
            0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
            0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
            0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
            4, 0xFFFFFFFF, 0xFFFFFFFF, 54, 57, 38, 31, 52, 22,
            25, 60, 1, 51, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
            0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 30,
            62, 53, 50, 8, 45, 10, 36, 58, 9, 16, 26, 19, 3, 14,
            49, 0, 23, 41, 12, 29, 43, 13, 39, 46, 24, 0xFFFFFFFF,
            0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 17, 0xFFFFFFFF,
            7, 42, 28, 32, 35, 48, 61, 21, 63, 40, 20, 55, 56,
            33, 11, 59, 18, 5, 44, 15, 37, 2, 47, 27, 6, 34, 0xFFFFFFFF,
            0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF
    };

    public static String decode(String inStr) {
        byte[] in = inStr.getBytes(UTF8_CHARSET);
        byte[] decBytes = new byte[in.length];
        int inPos = 0;
        int decodePos = 0;
        int inLen = in.length;

        do {
            if ((inLen - inPos) <= 3) {
                break;
            }

            int iTmp1 = (hashIndex[in[inPos + 1]] >> 4) & 3 & 0xFF;
            int iTmp2 = 4 * (hashIndex[in[inPos + 0]] & 0xFF);
            decBytes[decodePos + 0] = (byte) (iTmp1 | iTmp2);
            decBytes[decodePos + 1] = (byte) ((hashIndex[in[inPos + 2]] >> 2) & 0xF | 16 * (hashIndex[in[inPos + 1]] & 0xFF));
            int iIdx = in[inPos + 2] & 0xFF;
            int jIdx = in[inPos + 3] & 0xFF;
            decBytes[decodePos + 2] = (byte) (((hashIndex[iIdx] & 0xFF) << 6) | (hashIndex[jIdx] & 0xFF));
            decodePos += 3;
            inPos += 4;
        } while (true);

        //此处处理最后不被4整除的字节
        if ((inLen - inPos) == 3) {
            decBytes[decodePos + 0] = (byte) ((hashIndex[in[inPos + 1]] >> 4) & 3 | 4 * (hashIndex[in[inPos + 0]] & 0xFF));
            // fix bug #1
            //此处JAVA 不存在无符号整型，因此直接使用C++中的代码左移超过符号位的时候开始出现问题。此处需要使用JAVA 的无符号右移（>>>）
            decBytes[decodePos + 1] = (byte) ((hashIndex[in[inPos + 2]] << 26 >>> 28) | 16 * (hashIndex[in[inPos + 1]] & 0xFF));
            int tmpPos2 = (byte)((hashIndex[in[inPos + 2]]) << 6);//todo 此处计算有问题
            if (tmpPos2 != 0) {
                decBytes[decodePos + 2] = (byte) tmpPos2;
                decodePos += 3;
            } else {
                decodePos += 2;
            }
        } else if ((inLen - inPos) == 2) {
            //fix bug look for <bug #1>
            decBytes[decodePos + 0] = (byte) ((hashIndex[in[inPos + 1]] << 26 >>> 30) | 4 * (hashIndex[in[inPos + 0]] & 0xFF));
            //decBytes[decodePos + 1] = (byte) (16 * (hashIndex[in[inPos + 1]] & 0xFF)); // 一般此处为0，c++中字符串的末尾为\0，因此在返回字符串的时候我们习惯性减去一个字符
            int iTmp = (byte)(16 * (hashIndex[in[inPos + 1]] & 0xFF)); // 一般此处为0，c++中字符串的末尾为\0，因此在返回字符串的时候我们习惯性减去一个字符
            if (iTmp != 0) {
                decBytes[decodePos + 1] = (byte) iTmp;
                decodePos += 2;
            } else {
                decodePos += 1;
            }
        } else if ((inLen - inPos) == 1) {
            int iTmp =  (byte)(4 * (hashIndex[in[inPos + 0]] & 0xFF));
            if (iTmp != 0) {
                decBytes[decodePos + 0] = (byte) iTmp;
                decodePos += 1;
            }
        }
        //小于1则不处理
        if (decodePos < 1) {
            return new String("");
        }
        return new String(decBytes, 0, decodePos, UTF8_CHARSET);
    }

    public static String encode(String inStr) {
        byte[] in = inStr.getBytes(UTF8_CHARSET);
        System.out.println("raw len:" + in.length);
        byte[] encBytes = new byte[in.length * 2 + 4];

        int i = 0;
        int j = 0;
        int inLen = in.length;

        do {
            if ((inLen - i) <= 2) {
                break;
            }
            int b0 = 0x00FF & in[i + 0];
            int b1 = 0x00FF & in[i + 1];
            int b2 = 0x00FF & in[i + 2];
            int idx = b0 >> 2;
            encBytes[j + 0] = charArray[idx & 0x3F];
            idx = (b1 >> 4) | ((b0 << 4) & 0x30);
            encBytes[j + 1] = charArray[idx & 0x3F];
            idx = (b2 >> 6) | ((b1 << 2) & 0x3C);
            encBytes[j + 2] = charArray[idx & 0x3F];
            encBytes[j + 3] = charArray[b2 & 0x3F];
            i += 3;
            j += 4;
        } while (true);

        if ((inLen - i) > 0) {
            int b0 = 0x00FF & in[i + 0];
            encBytes[j + 0] = charArray[b0 >> 2];
            if ((inLen - i) == 2) {
                int b1 = 0x00FF & in[i + 1];
                encBytes[j + 1] = charArray[(b0 << 4) & 0x30 | (b1 >> 4)];
                encBytes[j + 2] = charArray[(b1 << 2) & 0x3C];
                j += 3;
            } else {
                encBytes[j + 1] = charArray[(b0 << 4) & 0x30];
                j += 2;
            }
        }
        if (j < 1) {
            return new String("");
        }

        System.out.println("enc len:" + j);
        return new String(encBytes, 0, j, UTF8_CHARSET);
    }

    /**
     * 获取低八位
     *
     * @param in
     * @return
     */
    public static byte lobyte(int in) {
        return (byte) (in & 0xFF);
    }

    /**
     * 获取高八位字节
     *
     * @param in
     * @return
     */
    public static byte hibyte(int in) {
        return (byte) ((in >> 8) & 0xFF);
    }

    public static void main(String[] args) {
        // TODO Auto-generated method stub
        try {
            String encodeString = "L5KgTMZ1OMk9Wv69xlhDU0gD6N4u_MduONHuKH-u_MZuKkTuKM-u_MkuONkuONT2cyrX6hgSx2_uAN4PJ2_scyg9tM-2c06Dx04gxygeZ5f2cl_1cykgTD6965PncaWu6N4PWME4WMTCTNkfTeHlJXWDZ51Hx04gT5TlOMH1TeZfOMZlWNruT5JzZeEmZ9d0OyrH6Nk96NElWyE2cl6DtM-2UugHRlW36eC16RT2ZR8fRl6ucXWSx0mgTM-4Tq6Sx5hStMTCOM-DWMQCTMHlTNQfTv6Fx0_uxNCNx0gscyrHG9dlT98TJ2hsZR8965_4L5CutM-PTNHmW9TlWeT2ZlTgTv6nUe4POq6nxe44oeT2UM4PWMQPTNQ4T9_zWMK46NT4WMEfT2EmT9_2WNWzZ9TfTv6YUNCRqk6JJ2JCL5PHR01Cx5Juce44oeTYTNKDouQ9oe-4TN-POvmmW9TfMv6fxyr4R0FuAhg06REgTv69xlhDU0gD6N4u_MduONHuKH-u_MZuKkTuKM-u_MkuONkuONT2xyu9Ua8wc94PJX8n60h3L51H6RdgTq606RJ9L5gYK0gH6M4DWq6wcyhDZR_uhyuF6M4PWME4WMTCTNZDW9ZDJ2rY6aJwL5_J6NCHZ9-lO5he6yE1WeKDTN_uJ2CnZ4rH6aEgOyT9Z5k9T5-CZ56zJX_DZ519kyrDZ54gc0hnc2Wjhauf6qk9_N-uTHT4JMJNWD64ZRJX6RKgxygeZ5f2Z06Dx04gT9k2c2hsZR_u6N4FTq6Ccy_nUykgoM-2x5gHU5PuR0uHtME2xXKgh4uyqq6fc2hEZ51HxykgTq6Fx0_uxNCNx0gscyrHG9dlT98TJ2_uxXWSUaHgTDmfJXWec2huxXWSA2kgTMQmTr7PW9c0J2uF65HgT9k1TMECTNkPOMcfTNQfJ2JCL5PHR01Cx5Juce44oeTYTNKDouQ9oe-4TN-POvmmW9TfMv6nca83U2hDc0uwxe4PTMKPJX8nUyWjRlWCcN4PJ2r0tM-1JX8sZR_8cyF56REgTv6ec94fJX8sZR_8cyF56RJOZ5Cut51Cxyf2UM4PWMQPTNQ4T9_zWMK46NT4WMEfT2EmT9_2WNWzZ9TfTv6fxyr4656wc2C56RJ9L5gYM2rF6MCYU5PsJX8SZl_1cykgU0hzcv6fxyr4R0FuAhg06REgTv6uxyrfc0hHUyuF6M4PTMQ1ONc4TMElJ2rYtMKYTD6fxyr4656wc2C56RJ9L5gYtMQ2c94DJMUNWN-mT9QCWMc0J2S0chg4AR8utMQ";
            //String encodeString = "ADJD6RWCxaKzOX_DU5hg";
            String decodeStringTest = decode(encodeString);
            System.out.println("the encode string : " + encodeString + " , the decode String : " + decodeStringTest);
            String decodeString = "{\"result\":true}";
            String encodeStringTest = encode(decodeString);
            System.out.println("the decode string : " + decodeString + " , the decode String : " + encodeStringTest);
            //simpleTest();
            //decodeTest();
        } catch (Exception e) {

        }
    }

    public static void decodeTest() throws IOException {
        decodeTmpDir();
        String encodeString = "L5KgTMZ1OMk9Wv69xlhDU0gD6N4u_MduONHuKH-u_MZuKkTuKM-u_MkuONkuONT2cyrX6hgSx2_uAN4PJ2_scyg9tM-2c06Dx04gxygeZ5f2cl_1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RR4");
            System.out.println(data4 + "\n\n");
            data4 = decode("xlJS60uYtM-fTv6Fx0_uxN42cyFXM2rF6MCex04YZ2JVo2rfcaW4xlJuJ2uF65HgT9k1TMECTNkPOMcfTNQfJX8Dx0WuclWOZ5Cut5Wwxq1zZ2sYZR8fcl_wc2k2U2hDc0uwxHWw6ykgTM-4Tq606RJ9L5gYM2rF6M4loeQYWe-2ZRZgTMH2c0_Vh2hDc0uwxe4DJ2PnU51eLr_1cykgTq6ec2r9Lr_Sx5kgTv6sZRhYZ0nkL5CutM-CTeKlTNK1TMc0OMZ2ZlJnc0nkAR8utM-2cyr4Z0n56RJ9L5gYt5_u62rCxaK2Z5mgWvm9J2WDZRWjq512x9CYU5PsJ2u9KlJnc0dgTv6DUe44oeTYTNKDouQ9oe-4TN-POvmmW9TfMv6bUXr3Uauf6M4f");
            System.out.println(data4 + "\n\n");
            data4 = decode("xXKgh4uyqq6e6XJwxM4PTz6Fx0_uxNCNx0gscyrHG9dlT98TJ2_uxXWSUaHgTDmfJXWec2huxXWSA2kgTMQmTr7PW9c0J2JCL5PHR01Cx5Juce44oeTYTNKDouQ9oe-4TN-POvmmW9TfMv6nca83U2hDc0uwxe4PTMKPJX8nUyWjRlWCcN4PJX8wc94PJ2uHtM-0OMHCT9K2cyueUauf6MCl65JfJX8sZR_u62gDxh6ucXWSx0mgTv6fZ5UuR0uY6yhmtM-2L0h1U0gD6N4u_MduONHuKH-u_MZuKkTuKM-u_MkuONkuONT2L5CuLM49WMHPTekfWM-1W9QfTNQ2ZRZgTMH2cyPnU-rfLC6uce4fJ2W9tMQ2cyPnU-rfLC6ucH1nx5kgxXhsxv6CtM-CTN-fTNK9WyECWN_HT9KCTeQDZed9WyZ4T0JeT9QfJX8sZR_u62gDxh6ucXWSx01OZ5Cut51Cxyf2cyPnUrgV6Ru3U2hDtMQ2x5gHU5PuR0uHtME265PncaWu6a_Sx5kgOMT4TMKfTed2Z5mgWvm9JX_nc2UuUNCsx0Wnxv6sLRW4cyg9tM-2Z0gYUyhYUrgex0Cfxyh46M4PJ21u65_3Z0gFx5hYUN4fJXTgTzklK9TDT9-DWNE4W9c2LX6PRl_1cykgTQ");
            System.out.println(data4 + "\n\n");

            data4 = decode("ADJD6RWCxaKzOX_DU5ksEX6nxahuEeSpE2uHEejPWeH1WMT4ovJ4LR_s6hgILvEIEYzJYYLsjA5rdDEsEX_SUyPuR0hYEejzIE2I1bDn1Z5NEzfzc0Wwc2kzOeTYTvfzc2r46RJ9R0WwU514EejDovJfZ5WVZ5UuR01nx5kzOzJex04YL5rDUaWu6q1Fx0JSxykDEzfzU2hDc0uwxugYZ5CuEejzTMEYTNQ9EzfzU2hDc0uwxugex0_uEejzTekzovJHxlUYxygn6rgCc2fzOzJjUa_fc9jwo0rfcaW4xlJuoX6SU27YZ0gFo2WYo0rfcyuY627w6yglx2PwZ5_8cyFyL5Put0uHtM-0OMHCT9KzovJ9LRSuEejPWMTCOvfzL5WwxugCc2fzOzJjUa_fc9jwo0uF6lU96yfYU2u0xD1ex04YZ0mwZR8fcl_wc2kw6yh065PwcyhDo0uex0mwTeQPW9Q9o9EfTMcfT9Q1TMH9TN-lONT0T9k0Wz1l65JfEzfzx062L5WnxvEIEeQzovJfZR_eLaTzOzEDWh7DWNj4Wed0OedfWeQ4TMk0OeKDWNKCONTfWe-sTeh3TeTIWNc4Tej0W9-fTMd0WeZITM-CTNdlTNT4TzfDWh7DTMjPWNE9OMjDTNdmW9EDWMKfOeElW9c0Te-9TqEsEXW4ZR_CcDEITvfzcyrD6514R0uHEejfovJH6R6uxygf6REzOzojzxVjSma2uj3ueJxHwGNubSowwEeueJ3HYb9wwEX2XEXS26NunL9uepdzovJHxlUYxygn6rgexlhYUvEIOMdmovJCcyPwZ5_3UyuF6qEIEeEfTMcFTNdFTNHdTNHITecIWN-zovJ9ZlJu6519Lyg4Rl_1cykzOeQsEXWec2huxXWjxl_TLRW4EeSxE2n4Ua89Oz7wL5CXUlWHxv10LR6wo2Wwxq1exzgnca89Uyg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nc2hHhRJsEejzLa_4cNjwo0uY627YZR8fcl_wc2kYU2u0xD1ex04YZ0mw6yh4Z5uso9-0OMHCT9KzovJex0146514Eejz5BzJYYLsjA5rdCl2XLRjnISQU2u0xB5IuOAkbO5hnY5Iu9jzovJ2c2gFEejzxygeZ5fzovJnURJwc2-zO26nxaWu3qfzL512xDEIEe-zovJex0CF6514Eejz5qJg");
            System.out.println(data4 + "\n\n");

            data4 = decode("xXKgh4uyqq6CcyPwZ5_3Uauf6M4DJ2Cw6yhstkWwx0PfZ5KdONc9T-f26yhYc0u4AM49oeQ2c0WD65hYc0uI6M4PTNdfR9-lW9Z2L5CuLM49WMHPTekfWM-1W9QfTNQ2ZXhSxy_3xXhFZ2hDtMKYTDmfWNEYkNTYTMKfTM-moedlT98TJ2rfcrg06RJ9L5gYtM-PWN-2ZR8fR0PSclKg5lszU2hDc0uwxugYZ5CuEejzTMEYTNQ9EzfzcyreL0rX6hgYZ5CuEejzZ0gFo2uncX_965kYx5gzL5PuTzEsEX8nZ0Fn60h3Z5W4L5gYEejPovJ06RJ9L5gYR0Ww6ykzOeEC3h42ZRZgTMH2cyPnU-rfLC6uce4fJ2W9tMQ2cyPnU-rfLC6ucH1nx5kgxXhsxv6CtM-CTN-fTNK9WyECWN_HT9KCTeQDZed9WyZ4T0JeT9QfJX8sZR_u62gDxh6ucXWSx01OZ5Cut51Cxyf2c94D3N-CWMQ4W9K1TD6fL5W4AR8utRUuZXQ2cyPnUrgV6Ru3U2hDtMQ265PncaWu6a_Sx5kgOMT0OMZDT9K2Z5mgWvm9JX8sZR_u62gDxh6ucXWSx0mgTv6bUXr3Uauf6M4f");
            System.out.println(data4 + "\n\n");
            String encodeString2 = "";
            data4 = decode(encodeString2);
            System.out.println(data4 + "\n\n");
            data4 = decode("");
            System.out.println(data4 + "\n\n");


            //nt=WIFI&upload_type=2&model=Coolpad 8730L&density=3.0&screensize=1080_1776&imei=359125051970000&build_number=4.3.042.P3.140118.8730L&app_version=1141&app_list=[{"version_name":"12.003","package_name":"com.iartsee.mobile2","package_action":1,"version_code":25}]&av=19&platApkVer=0&cs=0&platApkVerName=null&u=150100434b544d345202b834f43bc300&plateformVersionName=null
            //&s=2|155047493&pictype=webp&plat_key_ver=0&elapsedtime=93696234&an=4.3&plateformVersion=0&jvq_type=

        } catch (Exception e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }

    public static void simpleTest() {
        // TODO Auto-generated method stub
        String testStr = "ZR8fh2hDc0uwxH1nx5kgTzm9oe-2xXKgh4uyqq6Fx0_uxNCO6RnCcDsCJX8n60h3L51H6RdgTq6fLRnuxN49oeQ2L5CuLM49WMHPTekfWMT9OM-CWMk2xlJS60uYtMEfJX_1cykgxyu9Uv69ARW8Z0WwU514tMQ2ZRZgTMH2cyr4Z0n3clhftM-2ZlTgTv6n6aJ56RJOZ5CutMKYWvm4JXkgWNkfTMQfWMT4WM_HT9-9WeKlTNcfTyKDTNheZeTPTNQ2ZR8fcyFXM2rF6MCex04YU2u0xD1XZ5CuJ2rfcr6ucXWSx0mgTMTPJ2hsZR8965_4L5CutMd4TMH1TNH9JX8SZC_1cykgU0hzcv69tMEuW4T0TNQ1TNECJ2S0chg4AR8utMQ";
        try {
            String decStr = decode(testStr);
            System.out.println(decStr);
            String encStr;
            encStr = encode(decStr);
            System.out.println(encStr);
        } catch (Exception e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }

    public static void decodeTmpDir() throws IOException {
        File tmpFileDir = new File("tmp");
        File[] subFiles = tmpFileDir.listFiles();
        for (File sub : subFiles) {
            if (sub.getName().contains(".decode"))
                continue;

            String encodeSting = FileUtils.readFileToString(sub, "utf-8");
            FileUtils.writeStringToFile(new File(sub.getAbsolutePath() + ".decode"), decode(encodeSting), "utf-8");
        }
    }
}
